<template>
    <div class="container">
        <div>
            <img class="width-375 height-215" v-if="fileSpace" :src="fileSpace + '/images/cancellation-banner.png'" alt="">
        </div>
        <div class="main-bar pad-l-15 pad-r-15">
            <div class="row-bar flex flex-between mar-b-10" @click="getScanning">
                <div>
                    <img class="width-40 height-47.5" v-if="fileSpace" :src="fileSpace + '/images/cancellation-list-1.png'" alt="">
                </div>
                <div class="width-260 flex flex-between">
                    <div>
                        <div class="font-15 font-color font-w">扫码核销</div>
                        <div class="font-12 font-color-9">扫描顾客取货码，确认取货</div>
                    </div>
                    <div>
                        <img class="width-5 height-10" v-if="fileSpace" :src="fileSpace + '/images/arrow-right.png'" alt="">
                    </div>
                </div>
            </div>
            <div class="row-bar flex flex-between mar-b-10" @click="$pt.navigateTo({url:'/pages/home/store-cancellation/record-cancellation/main'})">
                <div>
                    <img class="width-40 height-47.5" v-if="fileSpace" :src="fileSpace + '/images/cancellation-list-2.png'" alt="">
                </div>
                <div class="width-260 flex flex-between">
                    <div>
                        <div class="font-15 font-color font-w">核销记录</div>
                        <div class="font-12 font-color-9">查看核销记录</div>
                    </div>
                    <div>
                        <img class="width-5 height-10" v-if="fileSpace" :src="fileSpace + '/images/arrow-right.png'" alt="">
                    </div>
                </div>
            </div>
            <div class="row-bar flex flex-between mar-b-10" v-if="statusIs" @click="$pt.navigateTo({url:'/pages/home/store-cancellation/writer-manage/main'})">
                <div>
                    <img class="width-40 height-47.5" v-if="fileSpace" :src="fileSpace + '/images/cancellation-list-3.png'" alt="">
                </div>
                <div class="width-260 flex flex-between">
                    <div>
                        <div class="font-15 font-color font-w">核销员管理</div>
                        <div class="font-12 font-color-9">设置门店的核销店员</div>
                    </div>
                    <div>
                        <img class="width-5 height-10" v-if="fileSpace" :src="fileSpace + '/images/arrow-right.png'" alt="">
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
import { parseShortCode } from '@/api/common'
export default {
  data() {
    return {
      statusIs: true,
      resData: {},
      count: 0
    }
  },
  onShow() {
    let personalType = this.$pt.getStorageSync('personalType')
    if (personalType === 0) {
      this.statusIs = false
    } else if (personalType === 1) {
      this.statusIs = true
    }
  },
  methods: {
    getScanning() {
      this.count++
      console.log('调用接口次数', this.count)
      //  未写完 需要学习
      this.$pt.scanCode({
        success: (res) => {
          console.log(res)
          let path = res.path
          if (!path) {
            this.$utils.showToast({
              title: '扫码异常，请扫码正确核销码!'
            })
            return
          }
          let pathAry = path.split('scene=')
          let index = pathAry[1].indexOf('&')
          if (index === -1) {
            this.parseShortCode(pathAry[1])
          } else {
            this.parseShortCode(pathAry[1].slice(0, index))
          }
        }
      })
    },
    parseShortCode(value) {
      let params = {}
      parseShortCode(value).then((response) => {
        if (response.isError) {
          this.resData = params
          if (this.getCustomerId) {
            this.$utils.setMyId(params.memberId)
            this.$root.$mp.appOptions.query = {}
            this.$pt.reLaunch({ url: '/pages/home/main' })
          } else {
            this.wxLogin(this.paramsData)
          }
          return
        }
        params = response.data
        console.log(params)
        if (params.path === 'pages/home/store-cancellation/orders-cancellation/main') {
          if (this.getCustomerId) {
            this.$pt.navigateTo({ url: '/pages/home/store-cancellation/orders-cancellation/main?memberId=' + params.memberId })
          } else {
            this.wxLogin(this.paramsData)
          }
        } else {
          this.$utils.showToast({
            title: '扫码异常，请扫码正确核销码!',
            duration: 1500
          })
        }
      }).catch({})
    }
  }
}
</script>
<style lang="less" scoped>
    .main-bar{
        margin-top: -34px;
        .row-bar{
            background: white;
            border-radius: 5px;
            padding: 27px 12px;
        }
    }
</style>
